package com.zxr.dao.impl;

import java.util.List;

import com.zxr.commen.Pageing;
import com.zxr.dao.HibernateBaseDAO;
import com.zxr.dao.SysroleDao;
import com.zxr.vo.Sysright;
import com.zxr.vo.Sysrole;

public class SysroleDaoImpl extends HibernateBaseDAO implements SysroleDao {

	public List<Sysrole> pageSysrole(Pageing page) {
		System.out.println("+++++"+page);
		String hql="from Sysrole where 1=1";
	
		System.out.println("+++++"+hql);
		return pages(hql,page);
	}

	public Long pageSysroleCount(Pageing page) {
		String hql="from Sysrole where 1=1";
		System.out.println("+++++"+hql);
		return pagesCount(hql);
	}

	public void addSysrole(Sysrole Sysrole) {
		save(Sysrole);

	}

	public void deleteSysrole(Sysrole sysrole) {
		
		delete(sysrole);

	}

	public void updateSysrole(Sysrole sysrole) {
		update(sysrole);

	}

	public Sysrole findSysroleById(String rightId) {
		String hql="from Sysrole s where s.roleid=?";
		Object[] params={rightId};
		List list=find(hql,params);
		Sysrole sysrole=null;
		if(!list.isEmpty()){
			sysrole=(Sysrole)list.get(0);
		}
		return sysrole;
	}

	public List<Sysrole> findAll() {
		String hql="from Sysrole s where 1=1";
		Object[] params={};
		List list=find(hql,params);
	
		return list;
	}

	public List<Sysrole> finfUserRole(int userid) {
		String hql="from Sysrole s where roleid in(select roleid from Sysuserrole where userid=(select userid from Administrator where userid=?))";
		Object[] params={userid};
		List list=find(hql,params);
	
		return list;
	}

}
